package test.zookeeper;

/**
 *
 *https://blog.csdn.net/quhongwei_zhanqiu/article/details/45648485

zookeeper服务器的四个状态
ServerState：LOOKING, FOLLOWING, LEADING, OBSERVING


QuorumPeer.start->run

start:
1.loadDataBase()
2.cnxnFactory.start()
	cnxnFactory = new NIOServerCnxnFactory()
	cnxnFactory.configure()--创建一个ZookeeperThread，打开一个NioServerSocketChannel
	cnxnFactory.start()--启动刚刚创建的ZookeeperThread
		ZookeeperThread(NIOServerCnxnFactory) //TODO
3.startLeaderElection()
	currentVote = new Vote(myid, getLastLoggedZxid(), getCurrentEpoch())

	getLastLoggedZxid--从zkDb里读出来的
	getCurrentEpoch--从snapDir/currentEpoch中读出

	设置myQuorumAddr（本机ip）
	electionAlg = createElectionAlgorithm(electionType);
		qcm = new QuorumCnxManager()[listener、SendWorker、RecvWorker] 
		QuorumCnxManager.listener.listen  
			创建ServerSocket->receiveConnection()->handleConnection()
				从流中读出sid（请求的zookeeper的myid）
				如果对方sid小于自身的myid，关闭socket连接（停止sendWorker和recvWorker），自身作为客户端和对方建立连接，启动sendWorker和recvWorker
				如果对方sid大于自身的myid，直接启动sendWorker和recvWorker
				
				sendWorker负责从queueSendMap中找到对应sid的queue并向其发送消息
				recvWorker负责把收到的消息放到recvQueue中，然后由FastLeaderElection进行处理
				
		electionAlg = new FastLeaderElection(qcm)
				new Messenger(qcm)=>
					WorkerSender.start 
						从FastLeaderElection的sendqueue中拉取消息，经过处理塞到QuorumCnxManager对应sid的sendqueue
					WorkerReceiver.start
						从QuorumCnxManager的recvQueue的中拉取消息，
				
run:
	LOOKING
		
	FOLLOWING
		
	LEADING
		
	OBSERVING
		
 *
 *
 *
 *
 *
 *
 */
public class ReadMe {

}
